﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Main_Ledger_ViewLedger : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    protected void BindGrid()
    {
        DataTable DTMain = new DataTable();
        DTMain.Columns.Add("LID");
        DTMain.Columns.Add("LNAME");
        DTMain.Columns.Add("LANAME");
        DTMain.Columns.Add("GRPNAME");
        DTMain.Columns.Add("ACTOPENING");
        strsql = "Select * from ACC_LEDMAST";
        DataTable DTLed = DU.getdata(strsql);
        if (DTLed.Rows.Count > 0)
        {
            for (int i = 0; i < DTLed.Rows.Count; i++)
            {
                DataRow DtRow = DTMain.NewRow();
                DtRow[0] = DTLed.Rows[i]["LID"].ToString();
                DtRow[1] = DTLed.Rows[i]["LNAME"].ToString();
                DtRow[2] = DTLed.Rows[i]["LANAME"].ToString();
                if (DTLed.Rows[i]["LID"].ToString() == DTLed.Rows[i]["PLID"].ToString())
                {
                    string strLed = "Select GNAME from ACC_GRPMAST Where GID='" + DTLed.Rows[i]["PGID"].ToString() + "'";
                    DataTable DT = DU.getdata(strLed);
                    if (DT.Rows.Count > 0)
                    {
                        DtRow[3] = DT.Rows[0]["GNAME"].ToString();
                    }
                }
               else
                {
                    string strLed = "Select LNAME from ACC_LEDMAST Where LID='" + DTLed.Rows[i]["PLID"].ToString() + "'";
                    DataTable DT = DU.getdata(strLed);
                    if (DT.Rows.Count > 0)
                    {
                        DtRow[3] = DT.Rows[0]["LNAME"].ToString();
                    }
                }

                DtRow[4] = DTLed.Rows[i]["ACTOPENING"].ToString();
                DTMain.Rows.Add(DtRow);
            }

        }
        grdDisplay.DataSource = DTMain;
        grdDisplay.DataBind();
        custPager.TotalPages = 2;

    }
    protected void grdDisplay_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdDisplay.PageIndex = e.NewPageIndex;
        BindGrid();
    }
    protected void grdDisplay_SelectedIndexChanged(object sender, EventArgs e)
    {
        string key = grdDisplay.SelectedDataKey.Value.ToString();
        Response.Redirect("EditLedger.aspx?lid="+key);
    }

    protected void custPager_PageChanged(object sender, CustomPageChangeArgs e)
    {
        grdDisplay.PageSize = e.CurrentPageSize;
        grdDisplay.PageIndex = e.CurrentPageNumber;

        BindGrid();
    }

    protected void grdDisplay_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Pager)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridview_alternate'");
                //e.Row.Attributes.Add("onclick", "this.className='rowselected'");
            }
            else if (e.Row.RowState == DataControlRowState.Normal)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridviewitem'");
                //e.Row.Attributes.Add("onclick", "this.className='rowselected'");
            }
        }
    }
}